using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.ProcessFlow;
using emp.Model;
using System.Globalization;
using emp.SqlServerDAL;


public partial class DataTransfer_DDR_Modify : System.Web.UI.Page
{
    private int DDR_ID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //if (HttpContext.Current.Session["USER_KEY"] == null)
            //{
            //    Response.Redirect("\\logon.aspx");
            //    return;
            //}
            DDR_ID = Int32.Parse(Request.Params["DDR_ID"]);
            Hidden_DDR_ID.Value = DDR_ID.ToString();
            DDRController dcon = new DDRController();
            DDRInfo ddrinfo = dcon.getDDRInfo(DDR_ID);
            DDR_Dup_Con.Text = ddrinfo.DDR_Dup_Con;
            DDR_Name.Text = ddrinfo.DDR_Name;
            DDR_Source_Table.Text = ddrinfo.DDR_Source_Table;
            DDR_Destination_Table.Text = ddrinfo.DDR_Destination_Table;
            DDR_Source_Key.Text = ddrinfo.DDR_Source_Key;
            DDR_Destination_Key.Text = ddrinfo.DDR_Destination_Key;
            DDR_Source_Field1.Text = ddrinfo.DDR_Source_Field1;
            DDR_Source_Field2.Text = ddrinfo.DDR_Source_Field2;
            DDR_Source_Field3.Text = ddrinfo.DDR_Source_Field3;
            DDR_Source_Field4.Text = ddrinfo.DDR_Source_Field4;
            DDR_Source_Field5.Text = ddrinfo.DDR_Source_Field5;
            DDR_Source_Field6.Text = ddrinfo.DDR_Source_Field6;
            DDR_Source_Field7.Text = ddrinfo.DDR_Source_Field7;
            DDR_Source_Field8.Text = ddrinfo.DDR_Source_Field8;
            DDR_Source_Field9.Text = ddrinfo.DDR_Source_Field9;
            DDR_Source_Field10.Text = ddrinfo.DDR_Source_Field10;
            DDR_Destination_Field1.Text = ddrinfo.DDR_Destination_Field1;
            DDR_Destination_Field2.Text = ddrinfo.DDR_Destination_Field2;
            DDR_Destination_Field3.Text = ddrinfo.DDR_Destination_Field3;
            DDR_Destination_Field4.Text = ddrinfo.DDR_Destination_Field4;
            DDR_Destination_Field5.Text = ddrinfo.DDR_Destination_Field5;
            DDR_Destination_Field6.Text = ddrinfo.DDR_Destination_Field6;
            DDR_Destination_Field7.Text = ddrinfo.DDR_Destination_Field7;
            DDR_Destination_Field8.Text = ddrinfo.DDR_Destination_Field8;
            DDR_Destination_Field9.Text = ddrinfo.DDR_Destination_Field9;
            DDR_Destination_Field10.Text = ddrinfo.DDR_Destination_Field10;
            DDR_Self.SelectedValue = ddrinfo.DDR_Self.ToString();
            DDR_Type.SelectedValue = ddrinfo.DDR_Type.ToString();
            DDR_Batch_Field.Text = ddrinfo.DDR_Batch_Field;
            DDR_IsValid_Field.Text = ddrinfo.DDR_IsValid_Field;
            DDR_Seq.Text = ddrinfo.DDR_Seq.ToString();

            initialdropdownlist();

            for (int i = 0; i < this.DDR_Source_ID.Items.Count; i++)
            {
                if (this.DDR_Source_ID.Items[i].Value == ddrinfo.DDR_Source_ID.ToString())
                {
                    this.DDR_Source_ID.Items[i].Selected = true;
                }
                if (this.DDR_Source_ID.Items[i].Selected == true)
                    break;
            }
            //DISMController icon = new DISMController();
            //icon.DropDownListBind(this.DDR_Source_ID, ddrinfo.DDR_Source_ID.ToString());
            //DDR_Dup_Type.SelectedValue = ddrinfo.DDR_Dup_Type.ToString();
            //DDR_Dup_Con.Text = ddrinfo.DDR_Dup_Con;
            //DDR_Seq.Text = ddrinfo.DDR_Seq.ToString();


        }
    }

    void initialdropdownlist()
    {
        //this.DDR_Source_ID.Items.Clear();
        //this.DDR_Source_ID.Items.Add(new ListItem("select", ""));
        //this.DDR_Source_ID.Items.Add(new ListItem("Web&IB Data", "0"));
        //emp.BLL.CampaignBll cpn = new emp.BLL.CampaignBll();
        //IList cpnlist = cpn.getCampaignList();

        //for (int i = 0; i < cpnlist.Count; i++)
        //{
        //    this.DDR_Source_ID.Items.Add(new ListItem(((CampaignInfo)cpnlist[i]).CAM_NAME, ((CampaignInfo)cpnlist[i]).CAM_QUR_ID.ToString()));
        //} 
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string sDDRName = "";
            string sDDRSourceTable = "";
            string sDDRDestinationTable = "";
            string sDDRSourceKey = "";
            string sDDRDestinationKey = "";
            string sDDRSourceField1 = "";
            string sDDRSourceField2 = "";
            string sDDRSourceField3 = "";
            string sDDRSourceField4 = "";
            string sDDRSourceField5 = "";
            string sDDRSourceField6 = "";
            string sDDRSourceField7 = "";
            string sDDRSourceField8 = "";
            string sDDRSourceField9 = "";
            string sDDRSourceField10 = "";
            string sDDRDestinationField1 = "";
            string sDDRDestinationField2 = "";
            string sDDRDestinationField3 = "";
            string sDDRDestinationField4 = "";
            string sDDRDestinationField5 = "";
            string sDDRDestinationField6 = "";
            string sDDRDestinationField7 = "";
            string sDDRDestinationField8 = "";
            string sDDRDestinationField9 = "";
            string sDDRDestinationField10 = "";
            int iDDRSelf = 0;
            int iDDRType = 0;
            string sDDRIsValid = "1";
            string sDDRBatchField = "";
            string sDDRIsValidField = "";
            int iDDRDupType = 1;
            string sDDRDupCon = "";
            int iDDRSeq = 0;
            if (DDR_Name.Text == "" || DDR_Name.Text == null)
            {
                sDDRName = "";
            }
            else 
            {
                sDDRName = DDR_Name.Text;
            }

            if (DDR_Source_Table.Text == "" || DDR_Source_Table.Text == null)
            {
                sDDRSourceTable = "";
            }
            else
            {
                sDDRSourceTable = DDR_Source_Table.Text;
            }

            if (DDR_Destination_Table.Text == "" || DDR_Destination_Table.Text == null)
            {
                sDDRDestinationTable = "";
            }
            else
            {
                sDDRDestinationTable = DDR_Destination_Table.Text;
            }

            if (DDR_Source_Key.Text == "" || DDR_Source_Key.Text == null)
            {
                sDDRSourceKey = "";
            }
            else
            {
                sDDRSourceKey = DDR_Source_Key.Text;
            }

            if (DDR_Destination_Key.Text == "" || DDR_Destination_Key.Text == null)
            {
                sDDRDestinationKey = "";
            }
            else
            {
                sDDRDestinationKey = DDR_Destination_Key.Text;
            }

            if (DDR_Source_Field1.Text == "" || DDR_Source_Field1.Text == null)
            {
                sDDRSourceField1 = "";
            }
            else
            {
                sDDRSourceField1 = DDR_Source_Field1.Text;
            }

            if (DDR_Source_Field2.Text == "" || DDR_Source_Field2.Text == null)
            {
                sDDRSourceField2 = "";
            }
            else
            {
                sDDRSourceField2 = DDR_Source_Field2.Text;
            }

            if (DDR_Source_Field3.Text == "" || DDR_Source_Field3.Text == null)
            {
                sDDRSourceField3 = "";
            }
            else
            {
                sDDRSourceField3 = DDR_Source_Field3.Text;
            }

            if (DDR_Source_Field4.Text == "" || DDR_Source_Field4.Text == null)
            {
                sDDRSourceField4 = "";
            }
            else
            {
                sDDRSourceField4 = DDR_Source_Field4.Text;
            }

            if (DDR_Source_Field5.Text == "" || DDR_Source_Field5.Text == null)
            {
                sDDRSourceField5 = "";
            }
            else
            {
                sDDRSourceField5 = DDR_Source_Field5.Text;
            }

            if (DDR_Source_Field6.Text == "" || DDR_Source_Field6.Text == null)
            {
                sDDRSourceField6 = "";
            }
            else
            {
                sDDRSourceField6 = DDR_Source_Field6.Text;
            }

            if (DDR_Source_Field7.Text == "" || DDR_Source_Field7.Text == null)
            {
                sDDRSourceField7 = "";
            }
            else
            {
                sDDRSourceField7 = DDR_Source_Field7.Text;
            }

            if (DDR_Source_Field8.Text == "" || DDR_Source_Field8.Text == null)
            {
                sDDRSourceField8 = "";
            }
            else
            {
                sDDRSourceField8 = DDR_Source_Field8.Text;
            }

            if (DDR_Source_Field9.Text == "" || DDR_Source_Field9.Text == null)
            {
                sDDRSourceField9 = "";
            }
            else
            {
                sDDRSourceField9 = DDR_Source_Field9.Text;
            }

            if (DDR_Source_Field10.Text == "" || DDR_Source_Field10.Text == null)
            {
                sDDRSourceField10 = "";
            }
            else
            {
                sDDRSourceField10 = DDR_Source_Field10.Text;
            }


            if (DDR_Destination_Field1.Text == "" || DDR_Destination_Field1.Text == null)
            {
                sDDRDestinationField1 = "";
            }
            else
            {
                sDDRDestinationField1 = DDR_Destination_Field1.Text;
            }

            if (DDR_Destination_Field2.Text == "" || DDR_Destination_Field2.Text == null)
            {
                sDDRDestinationField2 = "";
            }
            else
            {
                sDDRDestinationField2 = DDR_Destination_Field2.Text;
            }

            if (DDR_Destination_Field3.Text == "" || DDR_Destination_Field3.Text == null)
            {
                sDDRDestinationField3 = "";
            }
            else
            {
                sDDRDestinationField3 = DDR_Destination_Field3.Text;
            }

            if (DDR_Destination_Field4.Text == "" || DDR_Destination_Field4.Text == null)
            {
                sDDRDestinationField4 = "";
            }
            else
            {
                sDDRDestinationField4 = DDR_Destination_Field4.Text;
            }


            if (DDR_Destination_Field5.Text == "" || DDR_Destination_Field5.Text == null)
            {
                sDDRDestinationField5 = "";
            }
            else
            {
                sDDRDestinationField5 = DDR_Destination_Field5.Text;
            }


            if (DDR_Destination_Field6.Text == "" || DDR_Destination_Field6.Text == null)
            {
                sDDRDestinationField6 = "";
            }
            else
            {
                sDDRDestinationField6 = DDR_Destination_Field6.Text;
            }


            if (DDR_Destination_Field7.Text == "" || DDR_Destination_Field7.Text == null)
            {
                sDDRDestinationField7 = "";
            }
            else
            {
                sDDRDestinationField7 = DDR_Destination_Field7.Text;
            }


            if (DDR_Destination_Field8.Text == "" || DDR_Destination_Field8.Text == null)
            {
                sDDRDestinationField8 = "";
            }
            else
            {
                sDDRDestinationField8 = DDR_Destination_Field8.Text;
            }

            if (DDR_Destination_Field9.Text == "" || DDR_Destination_Field9.Text == null)
            {
                sDDRDestinationField9 = "";
            }
            else
            {
                sDDRDestinationField9 = DDR_Destination_Field9.Text;
            }


            if (DDR_Destination_Field10.Text == "" || DDR_Destination_Field10.Text == null)
            {
                sDDRDestinationField10 = "";
            }
            else
            {
                sDDRDestinationField10 = DDR_Destination_Field10.Text;
            }


            if (DDR_Batch_Field.Text == "" || DDR_Batch_Field.Text == null)
            {
                sDDRBatchField = "";
            }
            else
            {
                sDDRBatchField = DDR_Batch_Field.Text;
            }

            if (DDR_IsValid_Field.Text == "" || DDR_IsValid_Field.Text == null)
            {
                sDDRIsValidField = "";
            }
            else
            {
                sDDRIsValidField = DDR_IsValid_Field.Text;
            }
            iDDRSelf = Int32.Parse(DDR_Self.SelectedValue);
            iDDRType = Int32.Parse(DDR_Type.SelectedValue);
            sDDRIsValid = "1";
            int iDDRID = Int32.Parse(Hidden_DDR_ID.Value);
            int iDDRSourceID = Int32.Parse(DDR_Source_ID.SelectedValue);
            iDDRDupType = Int32.Parse(DDR_Dup_Type.SelectedValue);
            if (DDR_Dup_Con.Text == "" || DDR_Dup_Con.Text == null)
            {
                sDDRDupCon = "";
            }
            else
            {
                sDDRDupCon = DDR_Dup_Con.Text;
            }
            if (DDR_Seq.Text == "" || DDR_Seq.Text == null)
            {
                iDDRSeq = 0;
            }
            else
            {
                iDDRSeq = Int32.Parse(DDR_Seq.Text);
            }

            DDRInfo ddrinfo = new DDRInfo(
                iDDRID,
                iDDRSourceID,
                sDDRName,
                sDDRSourceTable,
                sDDRSourceKey,
                sDDRSourceField1,
                sDDRSourceField2,
                sDDRSourceField3,
                sDDRSourceField4,
                sDDRSourceField5,
                sDDRSourceField6,
                sDDRSourceField7,
                sDDRSourceField8,
                sDDRSourceField9,
                sDDRSourceField10,
                sDDRDestinationTable,
                sDDRDestinationKey,
                sDDRDestinationField1,
                sDDRDestinationField2,
                sDDRDestinationField3,
                sDDRDestinationField4,
                sDDRDestinationField5,
                sDDRDestinationField6,
                sDDRDestinationField7,
                sDDRDestinationField8,
                sDDRDestinationField9,
                sDDRDestinationField10,
                iDDRSelf,
                iDDRType,
                sDDRIsValid,
                sDDRBatchField,
                sDDRIsValidField,
                iDDRDupType,
                sDDRDupCon,
                iDDRSeq);

            DDRController iCon = new DDRController();
            iCon.UpdateDDR(ddrinfo);
            Response.Redirect("DDR_List.aspx?page=0");
        }
    }
}
